package org.ocean.online.auth;

import java.net.URL;
import java.net.URLConnection;

import org.apache.commons.lang.StringUtils;
import org.ocean.online.utils.CommonUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import sun.net.www.http.HttpClient;

public class AuthManager {

	private long expireTime;
	private static AuthManager instance = new AuthManager();
	protected Logger log = LoggerFactory.getLogger(this.getClass());
	private AuthManager(){
		Thread t = new Thread(new Runnable(){

			@Override
			public void run() {
				auth();
			}
		});
		t.start();
		
	}
	
	private void auth(){
		URL url;
		try {
			url = new URL( "http://localhost:8080/app/clienton");
			URLConnection conn=url.openConnection();
			conn.setDoOutput(true);
			conn.setConnectTimeout(20*1000);
			conn.connect();
			String status = conn.getHeaderField(0);
			if(StringUtils.isNotBlank(status) && status.contains("200")){
				String expireTime = CommonUtil.toString(conn.getInputStream());
				AuthManager.getInstance().setExpireTime(Long.valueOf(expireTime));
			}else{
				
			}
		} catch (Exception e) {
			
			log.error("",e);
		}
	}
	public static AuthManager getInstance(){
		return instance;
	}
	public long getExpireTime() {
		return expireTime;
	}

	public void setExpireTime(long expireTime) {
		this.expireTime = expireTime;
	}
	
	
}
